package com.gzsxy.esjy.eureka.listener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.netflix.eureka.server.event.EurekaInstanceRenewedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;

/**
 * 服务心跳监听器
 */
@Configuration
public class InstanceRenewListener implements ApplicationListener<EurekaInstanceRenewedEvent> {

    private static final Logger logger = LoggerFactory.getLogger(InstanceRenewListener.class);

    @Override
    public void onApplicationEvent(EurekaInstanceRenewedEvent event) {
        if (event != null){
            logger.info("心跳检测服务：【{}】,服务标识：【{}】,实例Id：【{}】",event.getAppName(),event.getServerId(),
                    event.getInstanceInfo() != null ? event.getInstanceInfo().getInstanceId() : "空");
        } else {
            logger.error("心跳检测服务：【未知】服务");
        }
    }
}
